package com.his.service.impl;

import com.his.entity.*;
import com.his.mapper.ScheduleMapper;
import com.his.service.IScheduleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 排班时间表 服务实现类
 * </p>
 *
 * @author Demoon Liu
 * @since 2022-02-20
 */
@Service
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule> implements IScheduleService {

    @Resource
    public ScheduleMapper scheduleMapper;

    @Override
    public ResponseResult selectAllSchedule() {
        List<Schedule>schedules=scheduleMapper.selectAllSchedule();
        if (Objects.isNull(schedules)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("schedule",schedules);
        return new ResponseResult(200, "查找信息成功", map);
    }

    @Override
    public ResponseResult selectAllSchedule_rule() {
        List<ScheduleRule>scheduleRules=scheduleMapper.selectAllSchedule_rule();
        if (Objects.isNull(scheduleRules)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("scheduleRule",scheduleRules);
        return new ResponseResult(200, "查找信息成功", map);
    }

    @Override
    public ResponseResult selectAllSchedule_rule_item() {
        List<ScheduleRuleItem>scheduleRuleItems=scheduleMapper.selectAllSchedule_rule_item();
        if (Objects.isNull(scheduleRuleItems)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("scheduleRuleItem",scheduleRuleItems);
        return new ResponseResult(200, "查找信息成功", map);
    }

    @Override
    public ResponseResult insertSchedule(Schedule schedule) {
        LocalDateTime localDateTime=LocalDateTime.now();
        schedule.setDate(localDateTime);
        scheduleMapper.insertSchedule(schedule);
        return new ResponseResult(200, "添加信息成功", null);
    }

    @Override
    public ResponseResult insertSchedule_rule(ScheduleRule scheduleRule) {
        LocalDateTime localDateTime=LocalDateTime.now();
        scheduleRule.setOperatetime(localDateTime);
        scheduleMapper.insertScheduleRule(scheduleRule);
        return new ResponseResult(200, "添加信息成功", null);
    }

    @Override
    public ResponseResult insertSchedule_rule_item(ScheduleRuleItem scheduleRuleItem) {
        scheduleMapper.insertScheduleRuleItem(scheduleRuleItem);
        return new ResponseResult(200, "添加信息成功", null);
    }

    @Override
    public ResponseResult deleteSchedule(Schedule schedule) {
        scheduleMapper.deleteSchedule(schedule.getId());
        return new ResponseResult(200, "删除信息成功", null);
    }

    @Override
    public ResponseResult deleteSchedule_rule(ScheduleRule scheduleRule) {
        scheduleMapper.deleteScheduleRule(scheduleRule.getId());
        return new ResponseResult(200, "删除信息成功", null);
    }

    @Override
    public ResponseResult deleteSchedule_rule_item(ScheduleRuleItem scheduleRuleItem) {
        scheduleMapper.deleteScheduleRuleItem(scheduleRuleItem.getId());
        return new ResponseResult(200, "删除信息成功", null);
    }

    @Override
    public ResponseResult selectScheduleBydid(Schedule schedule) {
        List<Schedule> schedules=scheduleMapper.selectScheduleBydid(schedule.getDeptid());
        if (Objects.isNull(schedules)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("schedule",schedules);
        return new ResponseResult(200, "查找信息成功", map);
    }

    @Override
    public ResponseResult selectSchedule_ruledid(ScheduleRule scheduleRule) {
        List<ScheduleRule> scheduleRules=scheduleMapper.selectSchedule_ruledid(scheduleRule.getDeptid());
        if (Objects.isNull(scheduleRules)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("scheduleRule",scheduleRules);
        return new ResponseResult(200, "查找信息成功", map);
    }

    @Override
    public ResponseResult selectSchedule_rule_itemsid(ScheduleRuleItem scheduleRuleItem) {
        List<ScheduleRuleItem> scheduleRuleItems=scheduleMapper.selectSchedule_rule_itemsid(scheduleRuleItem.getSkruleid());
        if (Objects.isNull(scheduleRuleItems)) {
            return new ResponseResult(250, "查找信息失败", null);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("scheduleRuleItem",scheduleRuleItems);
        return new ResponseResult(200, "查找信息成功", map);
    }
}
